<?php


namespace app\partneradmin\controller;


use app\common\controller\partneradmin\Base;
use app\partneradmin\model\Partner;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;

class Appbase extends Base
{

    protected $noNeedLogin = [];

    protected $model;


    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\partneradmin\model\AppBase;
    }

    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        if ($this->request->isPost()) {
            $page = $this->request->post('page', 1);
            $size = $this->request->post('page_size', 10);
            $sort = $this->request->post('sort', 'status');
            $order = $this->request->post('order', 'desc');
            $adminId = $this->request->post('admin_id', '');
            $title = $this->request->post('title', '');
            $switch = $this->request->post('switch', '');
            $partnerId = $this->admin['partner_id'];
            $partner = Partner::get($partnerId);
            $appids = explode(',', $partner['app_id']);
            $where['id'] = ['in', $appids];
            if ($adminId != '') {
                $where['admin_id'] = $adminId;
            }
            if ($switch != '') {
                $where['switch'] = $switch;
            }
            if ($title != '') {
                $where['title'] = ['like', '%' . $title . '%'];
            }
            $where['is_del'] = 0;
            $list = $this->model
                ->field('*')
                ->where($where)
                ->page($page, $size)
                ->order($sort, $order)
                ->select();
            $total = $this->model->where($where)->count('id');
            $totalPage = ceil($total / $size);
            $data = [
                'total' => $total,
                'list' => $list,
                'totalPage' => $totalPage
            ];
            $this->success('列表', '', $data);
        }
    }

    /**
     * 禁止新增
     */
    public function add()
    {
        $this->error('禁止新增');
        //   parent::add(); // TODO: Change the autogenerated stub
    }

    /**
     * 禁止新增
     */
    public function edit($ids = null)
    {
        $this->error('禁止编辑');
        //   parent::add(); // TODO: Change the autogenerated stub
    }

    /**
     * 删除（软删）
     */
    public function del($ids = "")
    {
        $this->error('禁止删除！');
    }
}